Step 1 - Use the Kanzi Engine API to load a Kanzi binary
When you create a new Kanzi Studio project with C++ application, Kanzi Studio creates a project with a Microsoft Visual Studio solution that includes the Kanzi application template source code.
Kanzi creates a Kanzi Studio project in <KanziWorkspace>/Projects/<ProjectName>/Tool_project directory and the structure for the Visual Studio solution for your project in <KanziWorkspace>/Projects/<ProjectName>/Application:
- bin directory contains the binaries and configuration files of your project.
- configs directory contains the configuration files for different platforms. By default Kanzi creates configuration files for several different platforms. The recommended platform for developing Kanzi applications is Microsoft Visual Studio 2010. See Deploying Kanzi applications.
- src contains the source code for your project.
Assets for the tutorial
The starting point of this tutorial is stored in <KanziWorkspace>/Tutorials/API tutorial:
- Tool_project contains the Kanzi Studio project which contains the application structure and resources you use in this tutorial. Whenever you make changes to this project, to see the result in your application, export the project to a .kzb binary. See Using .kzb binaries.
- Application/bin contains the Programmer_tutorial.kzb binary file generated from the Kanzi Studio project, and .png image files that the application you create in this tutorial uses.
You can find the completed tutorial in <KanziWorkspace>/Examples/Programmer_tutorial.
Use the Kanzi Engine API to load a Kanzi binary
To use the Kanzi Engine API to load a Kanzi binary:
- In Kanzi Studio open the <KanziWorkspace>/Tutorials/API tutorial/Tool_project/Programmer_tutorial.kzproj Kanzi Studio project and select > Export KZB > Export KZB Binary.
Kanzi Studio creates the .kzb binary and configuration files from your Kanzi Studio project. Kanzi Studio stores the exported files in <KanziWorkspace>/Projects/<ProjectName>/Application/bin or the location you specify in the Binary Export Directory property in > . The .kzb binary file contains all nodes and resources from your Kanzi Studio project, except the resources you mark in a localization table as locale packs.
When you run your Kanzi application from Visual Studio, your Visual Studio solution reads these files to create your Kanzi application.
- In Visual Studio open the solution stored in <KanziWorkspace>/Tutorials/API tutorial/Application/configs/platforms/win32/Programmer_tutorial.sln, set the Programmer_tutorial as your startup project, and open the programmer_tutorial.cpp file.
The programmer_tutorial.cpp file contains the minimum amount of code required for loading a Kanzi application. In this tutorial you create the logic of your application in this file.
// The kanzi.hpp header includes almost all Kanzi Engine functionality.
// To fine-tune your application you can include only the relevant headers.
// See API reference.
#include <kanzi/kanzi.hpp>
using namespace kanzi;
class ProgrammerTutorialApplication: public Application
{
// In the onConfigure function you can tell your Kanzi application which .kzb binary
// to load, enable performance information in your application, and set how many threads
// you want to use for loading the application resources.
// See Reference for application configuration.
virtual void onConfigure(ApplicationProperties& configuration) KZ_OVERRIDE
{
configuration.binaryName = "Programmer_tutorial.kzb.cfg";
}
// In the onKeyInputEvent function you handle the key input in your application.
virtual void onKeyInputEvent(const KzsInputEventKey* inputData) KZ_OVERRIDE
{
KzsInputKey button = kzsInputEventKeyGetButton(inputData);
if (button == KZS_KEY_ESC || button == KZS_KEY_Q || button == KZS_KEY_BACKSPACE)
{
quit();
}
}
// In the registerMetadataOverride function you can register the metadata,
// such as components and property types. In this example you register the
// Kanzi components. Kanzi components is a module that contains most
// of the Kanzi components, such as the Grid List Box 3D.
virtual void registerMetadataOverride(ObjectFactory& /*factory*/) KZ_OVERRIDE
{
Domain* domain = getDomain();
domain->registerModule<KanziComponentsModule>("kanzi_components");
}
};
// To work with the main function in the Application framework you need to
// return your application in the createApplication function. The main
// function then passes the control to the main loop defined in your
// Application class.
Application* createApplication()
{
return new ProgrammerTutorialApplication;
}
- In Visual Studio select one of the solution configurations for your version of Visual Studio and run your application.
For example, if you are still developing your application, select the GL_vs2010_Debug configuration. If you want to create a production version of your Kanzi application, select one of the available release configurations.
When you build and run the program, Kanzi loads the .kzb file and shows the application content.
During an application launch Kanzi:- Calls the
onConfigure
entry point function, where you specify the configuration. For example, which Kanzi Studio project binary files (.kzb) you want the application to load and the application window size. - Loads the .kzb binary file to memory, which makes it available to the application.
- When Kanzi completes the loading of the project, it calls the
onProjectLoaded
function. In the next steps of this tutorial you add the application functionality in this function.
< PREVIOUS STEP
NEXT STEP >
See also
Reference for application configuration
Using .kzb binaries
Deploying Kanzi applications
API reference
Open topic with navigation